package com.tinycloud.miracll.product.service.impl;

import java.util.List;

import com.tinycloud.common.core.text.UUID;
import com.tinycloud.common.core.utils.DateUtils;
import com.tinycloud.common.core.utils.SecurityUtils;
import com.tinycloud.common.datasource.annotation.Master;
import com.tinycloud.common.datasource.annotation.Slave1;
import com.tinycloud.miracll.product.domain.ProductLine;
import com.tinycloud.miracll.product.service.IProductLineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tinycloud.miracll.product.mapper.ProductPointMapper;
import com.tinycloud.miracll.product.domain.ProductPoint;
import com.tinycloud.miracll.product.service.IProductPointService;

/**
 * 点位管理Service业务层处理
 * 
 * @author tiny
 * @date 2021-08-25
 */
@Service
@Master
public class ProductPointServiceImpl implements IProductPointService 
{
    @Autowired
    private ProductPointMapper productPointMapper;
    @Autowired
    private IProductLineService productLineService;

    /**
     * 查询点位管理
     * 
     * @param id 点位管理主键
     * @return 点位管理
     */
    @Override
    public ProductPoint selectProductPointById(String id)
    {
        return productPointMapper.selectProductPointById(id);
    }

    /**
     * 查询点位管理列表
     * 
     * @param productPoint 点位管理
     * @return 点位管理
     */
    @Override
    public List<ProductPoint> selectProductPointList(ProductPoint productPoint) {
        List<ProductPoint> productPointList = productPointMapper.selectProductPointList(productPoint);
        for (ProductPoint productPointTem: productPointList) {
            String productLineID = productPointTem.getProductLineId();
            ProductLine productLine = productLineService.selectProductLineById(productLineID);
            productPointTem.setProductLine(productLine);

        }
        return productPointList;
    }

    /**
     * 新增点位管理
     * 
     * @param productPoint 点位管理
     * @return 结果
     */
    @Override
    public int insertProductPoint(ProductPoint productPoint)
    {
        productPoint.setCreateTime(DateUtils.getNowDate());
        productPoint.setId(UUID.randomUUID().toString());
        productPoint.setCreateTime(DateUtils.getNowDate());
        productPoint.setCreateBy(SecurityUtils.getUsername());
        return productPointMapper.insertProductPoint(productPoint);
    }

    /**
     * 修改点位管理
     * 
     * @param productPoint 点位管理
     * @return 结果
     */
    @Override
    public int updateProductPoint(ProductPoint productPoint)
    {
        productPoint.setUpdateTime(DateUtils.getNowDate());
        return productPointMapper.updateProductPoint(productPoint);
    }

    /**
     * 批量删除点位管理
     * 
     * @param ids 需要删除的点位管理主键
     * @return 结果
     */
    @Override
    public int deleteProductPointByIds(String[] ids)
    {
        return productPointMapper.deleteProductPointByIds(ids);
    }

    /**
     * 删除点位管理信息
     * 
     * @param id 点位管理主键
     * @return 结果
     */
    @Override
    public int deleteProductPointById(String id)
    {
        return productPointMapper.deleteProductPointById(id);
    }
}
